//格式化当前时间
const formatTime = (obj = {}) => {
	const {
		date,
		isHours = true,
		division = '-'
	} = obj
	const time = date ? new Date(date) : new Date()
	const year = time.getFullYear();
	const month = (time.getMonth() + 1).toString().padStart(2, '0');
	const day = time.getDate().toString().padStart(2, '0');
	const hours = time.getHours().toString().padStart(2, '0');
	const minutes = time.getMinutes().toString().padStart(2, '0');
	const seconds = time.getSeconds().toString().padStart(2, '0');
	return isHours ? `${year}${division}${month}${division}${day} ${hours}:${minutes}:${seconds}` :
		`${year}${division}${month}${division}${day}`;
}

//时间差计算
export const timeDifference = (faultDate, completeTime) => {
	var stime = Date.parse(new Date(faultDate));
	var etime = Date.parse(new Date(completeTime));
	// 两个时间戳相差的毫秒数
	var usedTime = etime - stime;
	// 计算相差的天数  
	var days = Math.floor(usedTime / (24 * 3600 * 1000));
	// 计算天数后剩余的毫秒数
	var leave1 = usedTime % (24 * 3600 * 1000);
	// 计算出小时数  
	var hours = Math.floor(leave1 / (3600 * 1000));
	// 计算小时数后剩余的毫秒数
	var leave2 = leave1 % (3600 * 1000);
	// 计算相差分钟数
	var minutes = Math.floor(leave2 / (60 * 1000));
	// var time = days + "天" + hours + "时" + minutes + "分";
	return {
		days,
		hours,
		minutes
	};
}

export default formatTime